class Solution:
    # @param s, a string
    # @return a boolean
    def isPalindrome(self, s):
    	i, j = 0, len(s)-1
    	while(i < j):
    		while not self.isAlph(s[i]):
    			i += 1
    			if i > j:
    				return True
    		while not self.isAlph(s[j]):
    			j -= 1
    			if j < i:
    				return True
    		if i < j and self.upper(s[i]) != self.upper(s[j]):
    			return False
    		i += 1
    		j -= 1
    	return True

    def upper(self, a):
    	if ord('a') <= ord(a) and ord(a) <= ord('z'):
    		a = chr(ord(a) - ord('a') + ord('A'))
    	return a

    def isAlph(self, a):
    	if ord('a') <= ord(a) and ord(a) <= ord('z'):
    		return True
    	if ord('A') <= ord(a) and ord(a) <= ord('Z'):
    		return True
    	if a in ['0','1','2','3','4','5','6','7','8','9']:
    		return True
    	return False

if __name__ == '__main__':
	so = Solution()
	a = '1a2'
	print(so.isPalindrome(a))